﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using OVS.Business;
using OVS.CoreDomain;
using OVS.CoreDomain.Business;

namespace OVS
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //
        }

        protected void btnLogin_click(object sender, EventArgs e)
        {
            string voterId = txtVoterId.Text;
            string password = txtPassword.Text;
            bool isAdmin = rdoAdmin.Checked;

            IBusinessLogin businessLogin = new BusinessLogin();
            ILoggedin loggedIn = businessLogin.Login(voterId, password, isAdmin);

            if (loggedIn.LoggedIn)
            {
                loggedIn.IsAdmin = isAdmin;
                loggedIn.VoterID = voterId;

                Session["LoggedIn"] = loggedIn;
                if (isAdmin)
                {
                    ClientScript.RegisterClientScriptBlock(this.GetType(), "setMenu", "parent.setMenu('Admin');", true);


                }
                else
                {
                    ClientScript.RegisterClientScriptBlock(this.GetType(), "setMenu", "parent.setMenu('Voter');", true);


                }
            }
            else
            {
                lblErrMsg.Text = "Please verify your password. Please note that password is case sensitive";
            }





        }

        protected void btnAdmin_Click(object sender, EventArgs e)
        {
            //Response.Redirect("Default.aspx?menu=Admin");
            
        }

        protected void btnVoter_Click(object sender, EventArgs e)
        {
            
            //Response.Redirect("Default.aspx?menu=Admin");
            
        }

    }
}
